package com.pw.study.arithmetic.linked

import com.pw.study.arithmetic.HeroNode
import com.pw.study.arithmetic.entities.HeroNode2

import scala.util.control.Breaks

/**
 * @Desc: 双向链表
 * @author: future
 * @since: 2022/5/29-15:35
 */
class FutureDoubleLinkedList() {
  /**
   * 显示节点信息
   */
  def listNodes(): Unit = {
    if(head.next==null){
      println("链表为空。。。")
      return
    }
    var tmp: HeroNode2 = head.next
    Breaks.breakable{
      while (true){
        if(tmp==null){
          Breaks.break()
        }
        println(s"list节点：${tmp.toString}")
        tmp=tmp.next
      }
    }


  }

  private val head: HeroNode2 = new HeroNode2(0, "", "")

  /**
   * 添加元素
   * @param node
   */
  def addNode(node: HeroNode2): Unit = {
    var tmp: HeroNode2 = head
    Breaks.breakable{
      while (true) {
        if(tmp.next==null){
          println("链表最后。。。")
          Breaks.break()
        }
        tmp=tmp.next
      }
    }
    tmp.next=node
    node.pre=tmp

  }



}
